<?php

//网站前台
class IndexController extends FrontBaseC {

    //网站首页
    public function actionIndex() {

        //侧边导航//所有的分类到二级，，，
        $arrSignMenu = CategoryModel::getListMenu(2);
        //print_r($arrSignMenu);exit;
        $this->assign('signMenu', $arrSignMenu);
        //banner图
        $arrAd = array(
            0 => AdvertisingModel::getListType(1),   //首页banner图
            1 => AdvertisingModel::getListType(2),            //banner底下图片
            2 => AdvertisingModel::getListType(3),            //banner测边图片
        );
        $this->assign('ad', $arrAd);
        //print_r($arrAd);exit;
        //首页轮播商品(姑娘们在败什么)
        $arrData = GoodsModel::getVariedGoods('', '', '', '', 1, '', '', 'default', '', '', false, true, 600);
        $this->assign('carousel', $arrData);



        //友情链接
/*        $arrLink = LinkModel::getList();
        $this->assign('link', $arrLink);*/



        //首页显示的产品数据
        $arrData = GoodsModel::getDataIndex();
        //print_r($arrData);exit;
        $this->assign('index_data', $arrData);
        $article[0] = ArticlesModel::getDataDetail(367);
        $article[1] = ArticlesModel::getDataDetail(368);
        $this->assign('article', $article);



        $this->render();
    }


    public function actionMcindex(){
        if(empty($_POST['mid']) || empty($_POST['cid'])){
            $this->ajaxReturn(array('status' => false));     
        }
        $data = GoodsModel::getDataIndexAjax($_POST['mid'], $_POST['cid']);
        $content = $this->renderPartial('indexdata', array('data' => $data['data']), true);
        $this->ajaxReturn(array('status' => true, 'content' => $content));        
    }



    /**
     * 分类页
     * 需要分页,
     * 每页显示多少
     * @return [type] [description]
     */
    public function actionGoods(){


        //导航
        $menus = array(
            //array('label' => '今日特价',     'url' => array('/front/index/onsale')),
            array('label' => '宝宝用品',     'url' => array('/front/index/onsale', 'cid' => 1)),
            array('label' => '宝宝食品',     'url' => array('/front/index/onsale', 'cid' => 36)),
            array('label' => '童装童鞋',     'url' => array('/front/index/onsale', 'cid' => 15)),
            array('label' => '玩具/学习',     'url' => array('/front/index/onsale', 'cid' => 22)),
            array('label' => '妈咪专区',     'url' => array('/front/index/onsale', 'cid' => 29)),
            array('label' => '明日预告',     'url' => array('/front/index/tomorrow')),
        );

        $this->assign('menus', $menus);





        $pagesize = 40;
        $page = Yii::app()->request->getParam('page');
        $mid = Yii::app()->request->getParam('mid');
        $cid = Yii::app()->request->getParam('cid');
        $tid = Yii::app()->request->getParam('tid');
        $order = Yii::app()->request->getParam('order');
        $extra = Yii::app()->request->getParam('extra');
        $page = empty($page) ? 1: $page;//第几页          
        $mid = empty($mid) ? '': $mid;//模块ID              
        $cid = empty($cid) ? '': $cid;//分类Id              
        $tid = empty($tid) ? '': $tid;//标签列表          
        $order = empty($order) ? 'default': $order;//排序        
        $extra = empty($extra) ? '': $extra;//额外 
        $arr = array(
            'pagesize' => $pagesize,
            'page' => $page,
            'mid' => $mid,
            'cid' => $cid,
            'tid' => $tid,
            'order' => $order,
        );
        $this->assign($arr);



        if(!$mid && !$cid){
            $this->error('请求出错');
        }


        //展示的商品
        if($order == 'default'){
            //1模块ID            2分类ID         3专场ID              4标签列表     5是否首页         6是否免邮             7额外条件    8排序                  9第几页       10每页展示条数       11是否打乱顺序      12是否缓存           13缓存时间
            $datas = GoodsModel::getVariedGoods($mid,$cid,'',$tid,'','', $extra, $order,$page,40,true,true,600);            
        }else{
            //1模块ID            2分类ID         3专场ID              4标签列表     5是否首页         6是否免邮             7额外条件    8排序                  9第几页       10每页展示条数       11是否打乱顺序      12是否缓存           13缓存时间
            $datas = GoodsModel::getVariedGoods($mid,$cid,'',$tid,'','', $extra, $order,$page,40,false,true,600);             
        }

        $this->assign('data', $datas);
        //这个模块下面的标签
        //这个分类下面的标签
        //这个分类下面的 子分类
        if($mid){
            //找出这个模块的标签列表
            $strTag = ModuleModel::getOne($mid,'TagListIDs');
        }else if($cid){
            $strTag = CategoryModel::getDataDetail($cid,'TagListIDs');           
            $this->assign('cat', CategoryModel::getListCatID($cid,2));
        }else{
            $strTag = '';
        }
        $tag = !empty($strTag) ? explode(',', $strTag) : array();
        $this->assign('tag', $tag);

        $this->render();
    }

    //每日特价
    public function actionOnsale(){



        //导航
        $menus = array(
            //array('label' => '今日特价',     'url' => array('/front/index/onsale')),
            array('label' => '宝宝用品',     'url' => array('/front/index/onsale', 'cid' => 1)),
            array('label' => '宝宝食品',     'url' => array('/front/index/onsale', 'cid' => 36)),
            array('label' => '童装童鞋',     'url' => array('/front/index/onsale', 'cid' => 15)),
            array('label' => '玩具/学习',     'url' => array('/front/index/onsale', 'cid' => 22)),
            array('label' => '妈咪专区',     'url' => array('/front/index/onsale', 'cid' => 29)),
            array('label' => '明日预告',     'url' => array('/front/index/tomorrow')),
        );

        $this->assign('menus', $menus);



        //$this->layout = 'theme.views.layouts.frontNoContent';
        $pagesize = 80;
        $page = Yii::app()->request->getParam('page');
        $cid = Yii::app()->request->getParam('cid');
        $page = empty($page) ? 1: $page;//第几页          
        $cid = empty($cid) ? '': $cid;//分类Id 
        $order = Yii::app()->request->getParam('order');
        $extra = Yii::app()->request->getParam('extra');
        $extra = empty($extra) ? '': $extra;//额外
        $order = empty($order) ? 9: $order;//排序
        $this->assign('cid',$cid); 
        $this->assign('page',$page);  
        $this->assign('order',$order); 
        if($order == 9){
    //1模块ID 2分类ID  3专场ID  4标签列表5是否首页6是否免邮 7额外条件    8排序 9第几页 10每页展示条数11是否打乱顺序 12是否缓存 13缓存时间
            $datas = GoodsModel::getVariedGoods('',$cid,'','','','', $extra, $order,$page,$pagesize,true,true,600);            
        }else{
    //1模块ID 2分类ID  3专场ID  4标签列表5是否首页6是否免邮 7额外条件    8排序 9第几页 10每页展示条数11是否打乱顺序 12是否缓存 13缓存时间
            $datas = GoodsModel::getVariedGoods('',$cid,'','','','', $extra, $order,$page,$pagesize,false,true,600);             
        }

        $this->assign('data', $datas);      
        $this->render();
    }


    //每日特价
    public function actionOnsale_bak(){
        //$this->layout = 'theme.views.layouts.frontNoContent';
        $pagesize = 40;
        $page = Yii::app()->request->getParam('page');
        $cid = Yii::app()->request->getParam('cid');
        $page = empty($page) ? 1: $page;//第几页          
        $cid = empty($cid) ? '': $cid;//分类Id 

        /*  
      $order = Yii::app()->request->getParam('order');
        switch ($order) {
            //销量从大到小
            case 1:
                $order = 'g.Sales DESC,g.GoodsID DESC';
                break;
            //价格从小到大
            case 2:
                $order = 'g.PromoPrice asc,g.GoodsID DESC';
                break;
            //价格从大到小
            case 3:
                $order = 'g.PromoPrice DESC,g.GoodsID DESC';
                break;
            //按人气排名
            case 4:
                $order = 'g.View DESC,g.GoodsID DESC';
                break;
            case 5:
                $order = 'zonghe';//综合排序，后面实现
                break;                                            
            default:
                # code...
                break;
        }
        */




        $this->assign('cid',$cid);  
        if(IS_AJAX){
            $datas = GoodsModel::getVariedGoods('',$cid,'','','','onsale',$page,$pagesize,false,true,600);
            $content = $this->renderPartial('data', array('data' => $datas), true);
            $this->ajaxReturn(array('status' => 1, 'content' => $content, 'count' => $data['count']));
        }        
        //$this->assign('data', $datas);      
        $this->render();
    }
    /**
     * 明日预告
     * @return [type] [description]
     */
    public function actionTomorrow(){

        //导航
        $menus = array(
            //array('label' => '今日特价',     'url' => array('/front/index/onsale')),
            array('label' => '宝宝用品',     'url' => array('/front/index/onsale', 'cid' => 1)),
            array('label' => '宝宝食品',     'url' => array('/front/index/onsale', 'cid' => 36)),
            array('label' => '童装童鞋',     'url' => array('/front/index/onsale', 'cid' => 15)),
            array('label' => '玩具/学习',     'url' => array('/front/index/onsale', 'cid' => 22)),
            array('label' => '妈咪专区',     'url' => array('/front/index/onsale', 'cid' => 29)),
            array('label' => '明日预告',     'url' => array('/front/index/tomorrow')),
        );

        $this->assign('menus', $menus);



        $pagesize = 100;
        $page = Yii::app()->request->getParam('page');
        $page = empty($page) ? 1: $page;//第几页          
        $order = Yii::app()->request->getParam('order');


        $this->assign('page',$page);  
        $this->assign('order',$order); 

        $datas = GoodsModel::getTomorrow($page,$pagesize,$order);
        $this->assign('data', $datas);      

        $this->render('onsale');        
    }

}
